import { BaseWindow } from "../../../component/window/BaseWindow";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { ImagesConst } from "../../resource/ImagesConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { PetItem } from "./PetItem";
import { RadioButtonGroup } from "../../../../fl/controls/RadioButtonGroup";
import { PetUtil } from "./info/PetUtil";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { PetAttrCalcUtil } from "./info/PetAttrCalcUtil";
import { GRadioButton } from "../../../../com/mui/controls/GRadioButton";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class PetSpiritBlessWindow
    
    export  class PetSpiritBlessWindow extends BaseWindow
    {
        constructor(arg1: SPetInfo=null)
        {
            super();
            this._attrLabelArray = [Language.getString(90040), Language.getString(90041), Language.getString(90042), Language.getString(90043), Language.getString(90044), Language.getString(90045), Language.getString(90046)];
            this._leftAttrTxtArray = [];
            this._leftAttrValueArray = [];
            this._rightAttrTxtArray = [];
            this._rightAttrValueArray = [];
            this._attrMutiTxtArray = [];
            this._levelTxtArray = [];
            this._levelRadioArray = [];
            this._petInfo = arg1;
            setSize(470, 470);
            title = Language.getString(90047);
            titleHeight = 30;
            this.init();
            return;
        }

        /* internal  */getCurFrame(arg1: int): int
        {
            var loc1=this.getShowMinLevel(arg1);
            arg1 = arg1 - loc1 + 2;
            if (arg1 < 1) 
            {
                arg1 = 1;
            }
            return arg1 * 5;
        }

        /* internal  */init(): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            ObjCreate.createBg(18, 45, 433, 75, this);
            this.addChild(new GImageBitmap("PetBlessBg.png", 135, 58));
            this.addChild(new GImageBitmap("PetSpiritBlessLevel.png", 145, 68));
            this._blessLevelTxt = ObjCreate.createTextField("", 300, 70, 220, 30, this, new GTextFormat(FontUtil.xingkaiName, 24, 65280));
            this._blessLevelTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createBg(18, 125, 433, 225, this);
            ObjCreate.createBg(18, 125, 433, 25, this, ImagesConst.TileBg);
            ObjCreate.createTextField(Language.getString(90049), 190, 130, 200, 20, this, new GTextFormat(FontUtil.songtiName, 14, 15859633));
            ObjCreate.createBg(35, 160, 150, 175, this);
            this.addChild(new GImageBitmap("CurrentLabel.png", 35, 160));
            this._leftSpiritTxt = ObjCreate.createTextField("", 80, 165, 200, 20, this, GlobalStyle.textFormatOrange);
            this._leftStrSpiritTxt = ObjCreate.createTextField("", 80, 185, 200, 20, this, GlobalStyle.textFormatOrange);
            ObjCreate.createBg(285, 160, 150, 175, this);
            this.addChild(new GImageBitmap("BlessLabel.png", 285, 160));
            this._rightAttrSprite = new Object /* flash.display.Sprite */();
            this.addChild(this._rightAttrSprite);
            this._rightTipTxt = ObjCreate.createTextField("", 305, 245, 95, 20, this);
            this._rightTipTxt.htmlText = Language.getString(54617);
            this._rightTipTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._rightTipTxt.visible = false;
            this._rightSpiritTxt = ObjCreate.createTextField("", 330, 165, 200, 20, this._rightAttrSprite, GlobalStyle.textFormatOrange);
            this._rightStrSpiritTxt = ObjCreate.createTextField("", 330, 185, 200, 20, this._rightAttrSprite, GlobalStyle.textFormatOrange);
            this._nameTxt = ObjCreate.createTextField("", 190, 165, 95, 20, this, new GTextFormat(FontUtil.songtiName, 16, 16742658));
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            ObjCreate.createBg(215, 200, 38, 38, this, ImagesConst.PackItemBg);
            this._petItem = new PetItem();
            this._petItem.isDragAble = false;
            this._petItem.isDropAble = false;
            this._petItem.setSize(32, 32);
            this._petItem.move(217, 202);
            this.addChild(this._petItem);
            var loc1=ObjCreate.createBg(265, 290, 58, 43, this, ImagesConst.ArrowHead);
            loc1.rotation = 180;
            this._acceptBtn = ObjCreate.createGButton(Language.getString(90051), 200, 315, 70, 24, this, "ButtonSpecial");
            this._acceptBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onAcceptBtnClickHandler);
            ObjCreate.createBg(18, 355, 433, 105, this);
            ObjCreate.createBg(18, 355, 433, 25, this, ImagesConst.TileBg);
            ObjCreate.createTextField(Language.getString(90052), 205, 360, 200, 20, this, new GTextFormat(FontUtil.songtiName, 14, 15859633));
            this._tipTxt = ObjCreate.createTextField("", 28, 390, 415, 65, this);
            this._tipTxt.wordWrap = true;
            this._tipTxt.multiline = true;
            this._tipTxt.htmlText = Language.getString(90053);
            var loc5=0;
            while (loc5 < this._attrLabelArray.length) 
            {
                loc2 = this._attrLabelArray[loc5];
                ObjCreate.createTextField(loc2, 70, 210 + loc5 * 18, 50, 20, this, GlobalStyle.textFormat5);
                loc3 = ObjCreate.createTextField("60", 110, 210 + loc5 * 18, 50, 20, this, GlobalStyle.textFormat1);
                this._leftAttrTxtArray.push(loc3);
                ObjCreate.createTextField(loc2, 300, 210 + loc5 * 18, 50, 20, this._rightAttrSprite, GlobalStyle.textFormat5);
                loc3 = ObjCreate.createTextField("60", 340, 210 + loc5 * 18, 50, 20, this._rightAttrSprite, GlobalStyle.textFormat1);
                this._rightAttrTxtArray.push(loc3);
                (loc4 = ObjCreate.createTextField("", 380, 210 + loc5 * 18, 200, 20, this._rightAttrSprite, new GTextFormat(FontUtil.songtiName, 12, 11661311, true))).autoSize = flash.text.TextFieldAutoSize.LEFT;
                this._attrMutiTxtArray.push(loc4);
                ++loc5;
            }
            return;
        }

        /* internal  */createLevelObj(arg1: int): void
        {
            var loc3=null;
            var loc4=null;
            this._levelRadioGroup = new RadioButtonGroup("level");
            this._levelRadioGroup.addEventListener(flash.events.MouseEvent.CLICK, this.onLevelRadioGroupClickHandler);
            var loc1=this.getShowMinLevel(arg1);
            var loc2=loc1 + 9;
            var loc5=loc1;
            while (loc5 <= loc2) 
            {
                loc3 = ObjCreate.createTextField(loc5.toString(), 132 + (loc5 - loc1) * 31, 76, 20, 20, this);
                this._levelTxtArray.push(loc3);
                (loc4 = ObjCreate.createRadioButton("", 132 + (loc5 - loc1) * 31, 95, 20, 20, this)).group = this._levelRadioGroup;
                loc4.value = loc5;
                this._levelRadioArray.push(loc4);
                ++loc5;
            }
            return;
        }

        /* internal  */updateLevelObj(arg1: int): void
        {
            var loc2=null;
            var loc3=null;
            var loc1=this.getShowMinLevel(arg1);
            var loc4=0;
            while (loc4 < this._levelTxtArray.length) 
            {
                loc2 = this._levelTxtArray[loc4];
                loc2.text = (loc1 + loc4).toString();
                (loc3 = this._levelRadioArray[loc4]).value = loc1 + loc4;
                ++loc4;
            }
            return;
        }

        public updateByPetInfo(arg1: SPetInfo): void
        {
            this._petInfo = arg1;
            if (arg1) 
            {
                this._nameTxt.htmlText = PetUtil.getPetName(arg1);
                this._petItem.dragSource = arg1;
                this._leftSpiritTxt.text = Language.getStringByParam(54613, arg1.spirit);
                this._leftStrSpiritTxt.text = Language.getStringByParam(54614, arg1.strengthenSpirit);
                this._previewBlessLevel = this._blessLevel;
                if (this._blessLevel <= arg1.strengthenSpirit) 
                {
                    this._rightAttrSprite.visible = false;
                    this._rightTipTxt.visible = true;
                }
                else 
                {
                    this._rightAttrSprite.visible = true;
                    this._rightTipTxt.visible = false;
                    this._rightSpiritTxt.text = Language.getStringByParam(54613, Math.max(this._blessLevel, arg1.spirit));
                    this._rightStrSpiritTxt.text = Language.getStringByParam(54614, this._blessLevel);
                    this._previewCalcLevel = this.getPreviewCalcBlessLevel(this._previewBlessLevel);
                    this.updateAttrSprite(arg1);
                    this.updateMutiAttr(arg1, arg1.spirit, this._previewCalcLevel);
                }
            }
            return;
        }

        /* internal  */getPreviewBlessLevel(arg1: int): int
        {
            var loc1=0;
            var loc2=this._petInfo.strengthenSpirit;
            if (arg1 < loc2) 
            {
                if (loc2 <= 8) 
                {
                    loc1 = 8;
                }
                else 
                {
                    loc1 = loc2;
                }
            }
            else 
            {
                loc1 = arg1;
            }
            return loc1;
        }

        /* internal  */getPreviewCalcBlessLevel(arg1: int=-1): int
        {
            return Math.max(this._petInfo.spirit, this._petInfo.strengthenSpirit, arg1);
        }

        /* internal  */updateAttrSprite(arg1: SPetInfo): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc1=null;
            if (arg1) 
            {
                this._leftAttrValueArray = [];
                loc1 = arg1.fightAttribute;
                this._leftAttrValueArray.push(loc1.physicalAttack);
                this._leftAttrValueArray.push(loc1.magicAttack);
                this._leftAttrValueArray.push(loc1.physicalDefense);
                this._leftAttrValueArray.push(loc1.magicDefense);
                this._leftAttrValueArray.push(loc1.hit);
                this._leftAttrValueArray.push(loc1.jouk);
                this._leftAttrValueArray.push(loc1.physicalCrit + loc1.magicCrit);
                while (loc4 < this._leftAttrTxtArray.length) 
                {
                    (loc3 = this._leftAttrTxtArray[loc4]).text = this._leftAttrValueArray[loc4].toString();
                    ++loc4;
                }
            }
            return;
        }

        public get blessLevel(): int
        {
            return this._blessLevel;
        }

        public set blessLevel(arg1: int)
        {
            this._blessLevel = arg1;
            this._blessLevelTxt.text = this._blessLevel.toString();
            return;
        }

        /* internal  */selectedRadioByBlessValue(arg1: int): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            while (loc3 < this._levelRadioArray.length) 
            {
                loc1 = this._levelRadioArray[loc3];
                loc2 = int(loc1.value);
                if (loc2 < arg1) 
                {
                    loc1.enabled = false;
                }
                else if (loc2 != arg1) 
                {
                    loc1.enabled = true;
                }
                else 
                {
                    loc1.selected = true;
                    loc1.enabled = true;
                }
                loc1.drawNow();
                ++loc3;
            }
            return;
        }

        /* internal  */gotoFrameByBlessLevel(arg1: int): void
        {
            if (this._blessBarMc) 
            {
                this._blessBarMc.gotoAndStop(this.getCurFrame(arg1));
            }
            return;
        }

        /* internal  */getShowMinLevel(arg1: int): int
        {
            if (arg1 <= 13) 
            {
                return 8;
            }
            if (arg1 > 13 && arg1 <= 15) 
            {
                return arg1 - 5;
            }
            return 11;
        }

        /* internal  */updateMutiAttr(arg1: SPetInfo, arg2: int, arg3: int): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            var loc5=0;
            var loc6=0;
            if (arg1) 
            {
                loc1 = this.getMutiArray(arg1, arg2, arg3);
                loc6 = 0;
                while (loc6 < this._rightAttrTxtArray.length) 
                {
                    loc2 = loc1[loc6];
                    loc5 = this._leftAttrValueArray[loc6];
                    (loc4 = this._rightAttrTxtArray[loc6]).text = (loc5 + loc2).toString();
                    loc3 = this._attrMutiTxtArray[loc6];
                    if (loc2 < 0) 
                    {
                        loc3.htmlText = HTMLUtil.addColor("↓" + Math.abs(loc2), GlobalStyle.color7);
                    }
                    else if (loc2 != 0) 
                    {
                        loc3.htmlText = HTMLUtil.addColor("↑" + Math.abs(loc2), GlobalStyle.color5);
                    }
                    else 
                    {
                        loc3.htmlText = "";
                    }
                    ++loc6;
                }
            }
            return;
        }

        /* internal  */getMutiArray(arg1: SPetInfo, arg2: int, arg3: int): Array<any>
        {
            var loc1;
            (loc1 = []).push(PetAttrCalcUtil.getPhysicalAttackMutiBySpirit(arg1, arg2, arg3));
            loc1.push(PetAttrCalcUtil.getMagicAttackMutiBySpirit(arg1, arg2, arg3));
            loc1.push(PetAttrCalcUtil.getPhysicalDefenseMutiBySpirit(arg1, arg2, arg3));
            loc1.push(PetAttrCalcUtil.getMagicDefenseMutiBySpirit(arg1, arg2, arg3));
            loc1.push(PetAttrCalcUtil.getHitMutiBySpirit(arg1, arg2, arg3));
            loc1.push(PetAttrCalcUtil.getJoukMutiBySpirit(arg1, arg2, arg3));
            loc1.push(PetAttrCalcUtil.getCritMutiBySpirit(arg1, arg2, arg3));
            return loc1;
        }

        /* internal  */onLevelRadioGroupClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=(arg1.target as RadioButtonGroup).selection as GRadioButton;
            this._previewBlessLevel = loc1.value as int;
            this._rightSpiritTxt.text = this._previewBlessLevel.toString();
            this._previewCalcLevel = this.getPreviewCalcBlessLevel(this._previewBlessLevel);
            this.updateMutiAttr(this._petInfo, this._petInfo.spirit, this._previewCalcLevel);
            return;
        }

        /* internal  */onAcceptBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._petInfo) 
            {
                if (this._blessLevel < this._previewBlessLevel) 
                {
                    Alert.show(Language.getString(90054), null, Alert.OK);
                    return;
                }
                if (this._petInfo.strengthenSpirit > this._previewBlessLevel) 
                {
                    Alert.show(Language.getString(90055), null, Alert.OK);
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetUseBless, {"uid": this._petInfo.uid, "isGrowth": false}));
            }
            return;
        }

        public get petInfo(): SPetInfo
        {
            return this._petInfo;
        }

        /* internal */ /* var */_rightAttrTxtArray: Array<any>;

        /* internal */ /* var */_rightAttrValueArray: Array<any>;

        /* internal */ /* var */_attrMutiTxtArray: Array<any>;

        /* internal */ /* var */_petItem: PetItem;

        /* internal */ /* var */_levelRadioArray: Array<any>;

        /* internal */ /* var */_blessLevel: int;

        /* internal */ /* var */_previewBlessLevel: int;

        /* internal */ /* var */_previewCalcLevel: int;

        /* internal */ /* var */_levelTxtArray: Array<any>;

        /* internal */ /* var */_blessBarSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_blessBarMc: Object /* flash.display.MovieClip */;

        /* internal */ /* var */_blessLevelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_acceptBtn: GButton;

        /* internal */ /* var */_leftSpiritTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_leftStrSpiritTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_rightSpiritTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_rightStrSpiritTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_rightAttrSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_rightTipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_leftAttrTxtArray: Array<any>;

        /* internal */ /* var */_levelRadioGroup: RadioButtonGroup;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_petInfo: SPetInfo;

        /* internal */ /* var */_attrLabelArray: Array<any>;

        /* internal */ /* var */_leftAttrValueArray: Array<any>;
    }
